home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 32 / Mac Magazin and MacEasy Magazine CD - Issue 32.iso / Service / Basissoftware / CDIconKiller 1.4 Folder / sources / CDIconKiller.c < prev    next >
C/C++ Source or Header  |  1996-11-06  |  8KB  |  361 lines

  1. #ifndef __Assembler__
  2. #include    <Assembler.h>
  3. #endif
  4.  
  5. #include    "TrapAvailable.h"
  6. /*
  7. ; CDIconKiller © 1994, 1996 Quinn & Peter N Lewis, Fabrizio Oddone
  8. ; Version 1.0 written in 4 hours from 02:00 to 05:30 18/June/94
  9.  
  10. bug fixes, CD driver string in resource (suggested by Quinn),
  11. asm tweaks, cdev trickery, etc.
  12. (version 1.1 thru 1.4) by Fabrizio Oddone
  13.  
  14. ; Patches GetCatInfo, tests for Custom Icon attribute on
  15. ; CD-ROM files/folders, and clears it.
  16.  
  17. ; Detailed description:
  18.  
  19. ; now runs as a cdev so the patch affects only the Finder
  20. ; since there is no user interface, we can retain the old icon
  21.  
  22. ; macDev time:
  23. ;    check if we are running under System 7 or later
  24. ;        check if the patch is already installed
  25. ;        load the resource containing the driver strings
  26. ;        patch GetCatInfo
  27.  
  28. ; initDev time:
  29. ;    we are done, quit silently
  30.  
  31. ; GetCatInfo patch:
  32. ;   Test for GetCatInfo selector on _HFSDispatch, do nothing otherwise
  33. ;   Call thru
  34. ;   Return immediately on error or async call
  35. ;   Return immediately unless Custom Icon bit set
  36. ;   Walk the volume queue looking for the vRefNum of the GetCatInfo
  37. ;   If we don't find it, we leave
  38. ;   If the command key is down, we leave
  39. ;   We determine whether the driver refnum is known (yes/no custom icons)
  40. ;   If "no", then clear the custom icon bit
  41. ;   If "yes", then leave
  42. ;   If the driver refnum is NOT known, we scan the driver queue and update our lists
  43.  
  44.     include    'sysequ.a'
  45.     include    'fsequ.a'
  46.     include    'traps.a'
  47.  
  48. ; procedure ShowIcon (id: integer; delta_x: integer);
  49.     import    ShowIcon
  50. */
  51. //main    proc    export
  52.  
  53. //extern pascal void ShowIcon(short iconID, short pixels);
  54. static void mypatch(void);
  55.  
  56. #define    patchSize    (526)    // because of CodeWarrior asm limitations
  57. #define    HFSDispatchTrapNum    0x60
  58.  
  59. pascal long main(short message, short /*item*/, short /*numItems*/, short /*cPanelID*/, EventRecord */*theEvent*/, long cdevValue, DialogPtr /*cpDialog*/)
  60. {
  61. long    resp;
  62.  
  63. if (cdevValue) {
  64.     switch (message) {
  65.         case initDev:
  66.             return cdevGenErr;
  67.             break;
  68.         case macDev:
  69. // normally you shouldn't check against the System version but against individual features
  70. // but in this case we want to know whether custom icons are used by the Finder
  71.             if (TrapAvailable(_Gestalt)) {
  72.                 if (Gestalt(gestaltSystemVersion, &resp) == noErr)
  73.                     if (resp >= 0x700) {
  74.                         mypatch();
  75.                         return 1;
  76.                         }
  77.                 }
  78. // no _Gestalt => very old System (< 6.0.4)
  79.             return 0;    
  80.             break;
  81.         }
  82.     }
  83. return cdevValue;
  84. }
  85.  
  86. asm void mypatch(void)
  87. {
  88.     moveq    #HFSDispatchTrapNum,d0    // patch HFSDispatch
  89.     _GetOSTrapAddress
  90.     move.l    OurHFSDispatch,d0
  91.     cmp.l    (a0),d0
  92. // if the patch is already there do nothing
  93.     beq.s    bad
  94.     lea    oldHFSDispatch,a1
  95.     move.l    a0,(a1)
  96.  
  97.     subq.w    #4,sp
  98.     move.l    #'STR#',-(SP)
  99.     move.w    #128,-(sp)
  100.     _Get1Resource
  101.     move.l    (sp)+,d0
  102.     beq.s    bad
  103.     lea    stringH,a0
  104.     move.l    d0,(a0)    // remember string handle
  105.     move.l    d0,-(sp)
  106.     _DetachResource
  107.  
  108. //    move.l    #(EndHFSDispatch-OurHFSDispatch),d0
  109.     move.l    #patchSize,d0
  110.     _NewPtr    //Sys
  111. // this block is installed in the System heap anyway, because
  112. // the Finder calls our cdev with the current zone set to the System zone
  113. // (at least under 7.5.5!)
  114. // in theory we should install everything in the Finder heap since it now
  115. // belongs there; but since the Finder malfunctions when its heap is low
  116. // (maybe the current zone is not set to the Finder zone for this reason)
  117. // we refrain from forcing the Finder zone with GetZone/SetZone
  118.     bne.s    baddisposepref
  119.  
  120.     movea.l    a0,a1
  121.     lea    OurHFSDispatch,a0
  122.     move.l    #patchSize,d0
  123. //    move.l    #(EndHFSDispatch-OurHFSDispatch),d0
  124.     _BlockMove
  125.  
  126.     moveq    #HFSDispatchTrapNum,d0
  127.     movea.l    a1,a0
  128.     _SetOSTrapAddress    
  129.  
  130. //    MOVE.L    #0xffff0080,-(SP)
  131. //    JSR    ShowIcon
  132. bad:
  133.     rts
  134.  
  135. baddisposepref:
  136.     movea.l    stringH,a0
  137.     _DisposHandle
  138.     rts
  139.  
  140.  
  141. OurHFSDispatch:
  142.     cmp.w    #9,d0    // Test for GetCatInfo selector
  143.     bne.s    dontdoit
  144.     pea    continued
  145. dontdoit:
  146.     move.l    oldHFSDispatch,-(sp)    // Call thru
  147.     rts
  148.  
  149. continued:
  150.     tst.w    struct (DirInfo.ioResult)(a0)
  151.     bne.s    fin    // give up on error or async
  152.     
  153.     btst    #2,struct (DirInfo.ioDrUsrWds.frFlags)(a0)
  154.     beq.s    fin    // give up unless custom icon
  155.     
  156.     movem.l    a1/d1,-(sp)
  157.     
  158.     MOVE.L    A0,-(SP)
  159.     LEA    -sizeof(EventRecord)(SP),SP
  160.     MOVEA.L    SP,A0
  161.     MOVEQ    #0,D0
  162.     _OSEventAvail
  163.     BTST    #0,struct (EventRecord.modifiers)(A0)    //cmdKey
  164.     LEA    sizeof(EventRecord)(SP),SP
  165.     MOVEA.L    (SP)+,A0
  166.     bne.s    leave
  167.  
  168.     movea.l    0x358,a1    // first volume control block LMGetVCBQHdr()+2
  169.     move.w    struct (DirInfo.ioVRefNum)(a0),d1
  170. lop:
  171.     cmp.w    struct (VCB.vcbVRefNum)(a1),d1
  172.     bne.s    cont
  173.  
  174.     move.w    struct (VCB.vcbDRefNum)(a1),d1
  175. //    _Debugger
  176.     bsr    finddriverdontwantcustomicons
  177.     bne.s    clearcustombit
  178.     bsr    finddriverwantcustomicons
  179.     bne.s    leave
  180.     bsr.s    findDriverbyName
  181.     bra.s    leave
  182. clearcustombit:
  183.     bclr    #2,struct (DirInfo.ioDrUsrWds.frFlags)(a0)    // clear custom icon
  184.     bra    leave
  185. cont:
  186.     movea.l    (a1),a1    // next volume control block
  187.     move.l    a1,d0
  188.     bne.s    lop
  189.  
  190. leave:
  191.     movem.l    (sp)+,a1/d1
  192.     moveq    #0,d0
  193.     
  194. fin:
  195.     tst.w    d0
  196. notstfin:
  197.     rts
  198.  
  199. finddriverdontwantcustomicons:
  200.     move.l    a0,-(sp)
  201.     lea    lastskipthesedrivers,a0
  202.     move.w    d1,(a0)
  203.     lea    skipthesedrivers,a0
  204. loopfinddontwant:
  205.     cmp.w    (A0)+,D1
  206.     bne.s    loopfinddontwant
  207.     pea    lastskipthesedrivers+2
  208.     cmpa.l    (sp)+,A0
  209.     movea.l    (sp)+,a0
  210.     rts
  211.  
  212. finddriverwantcustomicons:
  213.     move.l    a0,-(sp)
  214.     lea    lastotherdrivers,a0
  215.     move.w    D1,(a0)
  216.     lea    otherdrivers,a0
  217. loopfindwant:
  218.     cmp.w    (A0)+,D1
  219.     bne.s    loopfindwant
  220.     pea    lastotherdrivers+2
  221.     cmpa.l    (sp)+,A0
  222.     movea.l    (sp)+,a0
  223.     rts
  224.  
  225. findDriverbyName:
  226.     movem.l    a0-a4/a6/d1/d3-d5,-(sp)
  227.     moveq    #0,d5
  228.     lea    nextfreedontwant,a3
  229.     tst.l    (a3)
  230.     bne.s    alreadyinitednfdw
  231.     st    d5
  232.     pea    skipthesedrivers
  233.     move.l    (sp)+,(a3)
  234. alreadyinitednfdw:
  235.     movea.l    (a3),a0
  236.     pea    lastskipthesedrivers
  237.     cmpa.l    (sp)+,a0
  238.     beq.s    plainexit
  239.     lea    nextfreewant,a4
  240.     tst.l    (a4)
  241.     bne.s    alreadyinitednfw
  242.     pea    otherdrivers
  243.     move.l    (sp)+,(a4)
  244. alreadyinitednfw:
  245.     movea.l    (a4),a0
  246.     pea    lastotherdrivers
  247.     cmpa.l    (sp)+,a0
  248.     beq.s    plainexit
  249.  
  250.  
  251.     movea.l    0x11C,a2    // LMGetUTableBase()
  252.     move.w    0x1d2,d3    // LMGetUnitTableEntryCount()
  253. loop:
  254.     move.l    (a2)+,d0
  255.     beq.s    endloop
  256.     movea.l    d0,a1
  257.  
  258. // a1 = curDCtlHndl
  259.  
  260.     movea.l    (a1),a1
  261.     move.l    /*struct (DCtlEntry.dCtlDriver)*/(a1),d0
  262.     beq.s    endloop
  263.     movea.l    d0,a0
  264.     btst    #6,(struct (DCtlEntry.dCtlFlags)+1)(a1)    // test for RAMDriver
  265.     beq.s    notram
  266.     move.l    (a0),d0
  267.     beq.s    endloop
  268.     movea.l    d0,a0
  269. notram:
  270.     move.w    d3,d4
  271.     sub.w    0x1d2,d4    // calc driver refnum -(unit num+1) LMGetUnitTableEntryCount()
  272.     subq.w    #1,d4
  273.     tst.b    d5
  274.     bne.s    firsttime
  275.     move.w    d4,d1
  276.     bsr    finddriverdontwantcustomicons
  277.     bne.s    endloop
  278.     bsr    finddriverwantcustomicons
  279.     bne.s    endloop
  280. firsttime:
  281.     lea    struct (DRVRHeader.drvrName)(a0),a0
  282.     moveq    #0,d2
  283.     move.b    (a0)+,d2
  284.     swap    d2
  285.     bsr    cmpallstrings
  286.     bne.s    endloopsavedriver
  287.     movea.l    a3,a1
  288.     bra.s    commonpart
  289. endloopsavedriver:
  290.     movea.l    a4,a1
  291. commonpart:
  292.     movea.l    (a1),a0
  293.     move.w    d4,(a0)+    // remember driver refnum
  294.     move.l    a0,(a1)
  295. endloop:
  296.     subq.w    #1,d3
  297.     bne    loop
  298. plainexit:
  299.     movem.l    (sp)+,a0-a4/a6/d1/d3-d5
  300.     rts
  301.  
  302. // input: a0 string, d2 (already in hi word) length
  303. // output: sets the flags
  304. // registers are saved&restored by the calling routine
  305. cmpallstrings:
  306.     movea.l    stringH,a6
  307.     movea.l    (a6),a6
  308.     move.w    (a6)+,d1
  309.     andi    #0xB,CCR
  310.     bra.s    thedbcc
  311. cmploop:
  312.     move.l    d2,d0
  313.     move.b    (a6)+,d0
  314.     movea.l    a6,a1
  315.     adda.w    d0,a6
  316.     _CmpString
  317. thedbcc:
  318.     dbeq    d1,cmploop
  319. cmpexit:
  320.     rts
  321.  
  322. skipthesedrivers:
  323.     ds.w    15
  324. lastskipthesedrivers:
  325.     dc.w    -1
  326. otherdrivers:
  327.     ds.w    63
  328. lastotherdrivers:
  329.     dc.w    -1
  330. nextfreedontwant:
  331.     dc.l    0
  332. nextfreewant:
  333.     dc.l    0
  334. stringH:
  335.     dc.l    0
  336. oldHFSDispatch:
  337.     dc.l    0xffffffff
  338.  
  339. EndHFSDispatch:
  340.  
  341.     
  342.  
  343. //    string    pascal
  344.  
  345. }
  346. //    endp
  347.     
  348. //    end
  349.     
  350. /*
  351. asm -wb "{active}"
  352. (evaluate "{active}" =~ "/(?*:)®1(?*)/" )> dev:null
  353. (evaluate "{active}" =~ "/(?*)®2.a/" )> dev:null
  354. link -rt INIT=128 -ra =ressysheap,reslocked -t INIT -c CDik -o "{®2}" "{active}.o" "{®1}ShowIcon.o"
  355. setfile -a B "{®2}"
  356.  
  357.  
  358.  
  359. dumpobj "{®1}SHOWICON.o"
  360. */
  361.